const WorkService = require("../../services/admin/WorkService")
const WorkController = {

    add:async(req,res)=>{
        const {title,introduction,detail} = req.body
        //调用servise模块更新数据
        const cover = req.file?`/workuploads/${req.file.filename}`:""


        await WorkService.add({title,introduction,detail,cover,editTime:new Date()})
            res.send({
                ActionType:"ok",
                
            })
        
    },
        getList:async(req,res)=>{
        const result = await WorkService.getList({_id:req.params.id})
        res.send({
            ActionType:"ok",
            data:result
        })
    }, 
    delList:async(req,res)=>{
        const result = await WorkService.delList({_id:req.params.id})
        res.send({
            ActionType:"delok",
        })
    },
    updateList:async(req,res)=>{
        const cover = req.file?`/workuploads/${req.file.filename}`:""
        const {title,introduction,detail,_id} = req.body
        await WorkService.updateList({
            _id,title,introduction,detail,
            cover,
            editTime:new Date()
        })

        res.send({   
                ActionType:"ok",
                
            })
    },


    // putList:async(req,res)=>{
    //     const result = await UserService.putList(req.body)
    //     // console.log(result)
    //     res.send({
    //         ActionType:"ok",
    //     })
    // },   


}
module.exports = WorkController
